const front_token_key = "supplier_token"
const front_user_name_key = "supplier_email"


class Auth {

    constructor() {
        // this.front_token = null
        // this.front_username = null
        this.front_token = localStorage.getItem(front_token_key) ? localStorage.getItem(front_token_key) : ""
        this.front_username = localStorage.getItem(front_user_name_key) ? localStorage.getItem(front_user_name_key) : ""
    }

    // 缓存token、用户信息
    setFrontAuth(token, username) {
        this.front_token = token
        this.front_username = username
        localStorage.setItem(front_token_key, token)
        localStorage.setItem(front_user_name_key, username)

    }

    // 删除token、用户信息，用来做用户登出
    delFrontAuth() {
        this.front_token = null
        this.front_username = null
        localStorage.removeItem(front_token_key)
        localStorage.removeItem(front_user_name_key)
    }
}

// 单例
const auth = new Auth()
export default auth
